﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.UI.Notifications;
using Windows.Data.Xml.Dom;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using App_s2b_unilasalle.Common.negocio;

// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237

namespace App_s2b_unilasalle
{
    /// <summary>
    /// A basic page that provides characteristics common to most applications.
    /// </summary>
    public sealed partial class MainPage : App_s2b_unilasalle.Common.LayoutAwarePage
    {

        List<AlunoxDisciplina> objAlunoDsc = new List<AlunoxDisciplina>();

        public MainPage()
        {
            this.InitializeComponent();
            
            /*
            #region Text-Notification-01
            var notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            var toastElements = notificationXml.GetElementsByTagName("text");
            toastElements[0].AppendChild(notificationXml.CreateTextNode("Você possui uma nova mensagem."));
            toastElements[1].AppendChild(notificationXml.CreateTextNode(@"Jairo Frantiesco está disponibilizando carona."));

            var toastNotification = new ToastNotification(notificationXml);
            ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
            #endregion
            */
        
        }

        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            /*
            WebService ws = new WebService(201160003, 123456);

            List<Dictionary<string, object>> wsListDsc = ws.buscaDadosWS();

            if (wsListDsc.Count() > 0)
            {
                Aluno alu = new Aluno();
                alu.IntAluMatricula = wsListDsc[0]["matricula"].ToString();
                alu.StrAluNome = wsListDsc[0]["nome"].ToString();

                Disciplina dsc;
                foreach (Dictionary<string, object> wsDsc in wsListDsc)
                {
                    dsc = new Disciplina(
                        Convert.ToInt32(wsDsc["cod_dsc"]),
                        wsDsc["nome_dsc"].ToString(),
                        wsDsc["professor"].ToString(),
                        wsDsc["predio"].ToString(),
                        wsDsc["sala"].ToString()
                    );
                    this.objAlunoDsc.Add(
                        new AlunoxDisciplina(
                            alu,
                            dsc,
                            Convert.ToDouble(wsDsc["g1"]),
                            Convert.ToDouble(wsDsc["g2"]),
                            Convert.ToDouble(wsDsc["substituicao"]),
                            Convert.ToDouble(wsDsc["frequencia"]),
                            wsDsc["dia"].ToString()
                        )
                    );
                }
            }

            */
            List<Disciplina> dsc = new List<Disciplina>();

            Aluno alu = new Aluno();
            alu.IntAluMatricula = "201160003";
            alu.StrAluNome = "Jairo Frantiesco";

            dsc.Add(new Disciplina(16, "Cálculo Diferencial e Integral", "Paulo Roberto Ribeiro Vargas", "15", "604"));
            dsc.Add(new Disciplina(2632, "Desenvolvimento Web II", "Ricardo de Moura Rivaldo", "1", "308"));
            dsc.Add(new Disciplina(2627, "Fundamentos de Engenharia de Software", "Aline Duarte Riva", "15", "701"));

            this.objAlunoDsc.Add(new AlunoxDisciplina(alu, dsc[0], 5.3, 7.6, 0.0, 94.3, 2, 3));
            this.objAlunoDsc.Add(new AlunoxDisciplina(alu, dsc[1], 6.8, 7.7, 0.0, 100.0, 5, 3));
            this.objAlunoDsc.Add(new AlunoxDisciplina(alu, dsc[2], 10.0, 8.0, 0.0, 97.4, 6, 3));

            bool mostrarNotificacao = false;
            int hoje = (Int32)Convert.ToDateTime(DateTime.Now).DayOfWeek+1;
            foreach (AlunoxDisciplina disc in this.objAlunoDsc)
            {
                if (disc.Dia == hoje)
                    mostrarNotificacao = true;
            }

            if (mostrarNotificacao)
            {
                #region Text-Notification-01
                var notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
                var toastElements = notificationXml.GetElementsByTagName("text");
                toastElements[0].AppendChild(notificationXml.CreateTextNode("Você possui aula hoje."));
                toastElements[1].AppendChild(notificationXml.CreateTextNode(@"Verifique sua sala!"));

                var toastNotification = new ToastNotification(notificationXml);
                ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
                #endregion
            }
        }

        /// <summary>
        /// Preserves state associated with this page in case the application is suspended or the
        /// page is discarded from the navigation cache.  Values must conform to the serialization
        /// requirements of <see cref="SuspensionManager.SessionState"/>.
        /// </summary>
        /// <param name="pageState">An empty dictionary to be populated with serializable state.</param>
        protected override void SaveState(Dictionary<String, Object> pageState)
        {
        }

        private void gridSala_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            if (this.Frame != null)
            {
                this.Frame.Navigate(typeof(Sala), objAlunoDsc);
            }
        }

        private void gridNotas_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            if (this.Frame != null)
            {
                this.Frame.Navigate(typeof(Nota), objAlunoDsc);
            }
        }

        private void gridFreq_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            if (this.Frame != null)
            {
                this.Frame.Navigate(typeof(Frequencia), objAlunoDsc);
            }
        }


    }
}
